package com.lcpdev.yourweather.model;

import android.icu.text.LocaleDisplayNames;
import android.os.Process;
import android.provider.ContactsContract;
import android.support.v4.view.GravityCompat;
import android.util.Log;
import android.widget.Toast;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * Created by LCP on 2017/2/9.
 * @ Email:chuge94@163.com
 * GitHub:https://github.com/linchupeng/YourWeather
 */

public class Common {
    public static final String CITYIDS="北京CN101010100上海CN101020100天津CN101030100重庆CN101040100"
            +"福州CN101230101厦门CN101230201泉州CN101230501漳州CN101230601三明CN101230801宁德CN101230301南平CN101230901龙岩CN101230701莆田CN101230401"
            +"广州CN101280101韶关CN101280201梅州CN101280401汕头CN101280501深圳CN101280601珠海CN101280701佛山CN101280800肇庆CN101280901湛江CN101281001河源CN101281201清远CN101281301云浮CN101281401\n" +
            "潮州CN101281501东莞CN101281601中山CN101281701阳江CN101281801揭阳CN101281901茂名CN101282001汕尾CN101282101"
            +"昆明CN101290101大理CN101290201红河CN101290301曲靖CN101290401保山CN101290501文山CN101290601玉溪CN101290701楚雄CN101290801普洱CN101290901昭通CN101291001临沧CN101291101怒江CN101291201\n" +
            "香格里拉CN101291301丽江CN101291401德宏CN101291501西双版纳CN101291601"
            +"南宁CN101300101崇左CN101300201柳州CN101300301来宾CN101300401桂林CN101300501桂林CN101300601 贺州CN101300701贵港CN101300801玉林CN101300901百色CN101301001钦州CN101301101河池CN101301201北海CN101301301防城港CN101301401"
            +"成都CN101270101攀枝花CN101270201自贡CN101270301南充CN101270501遂宁CN101270701巴中CN101270901泸州CN101271001宜宾CN101271101内江CN101271201资阳CN101271301乐山CN101271401眉山CN101271501\n" +
            "雅安CN101271701甘孜CN101271801阿坝CN101271901德阳CN101272001广元CN101272101"
            +"贵阳CN101260101遵义CN101260201黔南CN101260401黔东南CN101260501铜仁CN101260601毕节CN101260701六盘水CN101260801黔西南CN101260901"
            +"长沙CN101250101湘潭CN101250201株洲CN101250301衡阳CN101250401郴州CN101250501常德CN101250601益阳CN101250700娄底CN101250801邵阳CN101250901\n" +
            "岳阳CN101251001张家界CN101251101怀化CN101251201永州CN101251401湘西CN101251501"
            +"南昌CN101240101九江CN101240201上饶CN101240301抚州CN101240401宜春CN101240501吉安CN101240601赣州CN101240701景德镇CN101240801新余CN101241001鹰潭CN101241101"
            +"海口CN101310101三亚CN101310201东方CN101310202澄迈CN101310204儋州CN101310205琼海CN101310211文昌CN101310212乐东CN101310221"
            +"合肥CN101220101蚌埠CN101220201芜湖CN101220301淮南CN101220401马鞍山CN101220501安庆CN101220601宿州CN101220701阜阳CN101220801亳州CN101220901黄山CN101221001滁州CN101221101淮北CN101221201\n" +
            "宣城CN101221401六安CN101221501池州CN101221701"
            +"哈尔滨CN101050101齐齐哈尔CN101050201牡丹江CN101050301佳木斯CN101050401绥化CN101050501黑河CN101050601大兴安岭CN101050701伊春CN101050801大庆CN101050901七台河CN101051002鸡西CN101051101鹤岗CN101051201双鸭山CN101051301"
            +"长春CN101060101吉林CN101060201延吉CN101060301四平CN101060401通化CN101060501白城CN101060601辽源CN101060701松原CN101060801白山CN101060901\n"
            +"西安CN101110101咸阳CN101110200延安CN101110300榆林CN101110401渭南CN101110501商洛CN101110601安康CN101110701汉中CN101110801宝鸡CN101110901铜川CN101111001杨凌CN101111101\n"
            +"南京CN101190101无锡CN101190201镇江CN101190301苏州CN101190401南通CN101190501扬州CN101190601盐城CN101190701徐州CN101190801淮安CN101190901连云港CN101191001常州CN101191101泰州CN101191201宿迁CN101191301\n"
            +"杭州CN101210101湖州CN101210201嘉兴CN101210301宁波CN101210401绍兴CN101210501台州CN101210601温州CN101210701丽水CN101210801金华CN101210901衢州CN101211001舟山CN101211101\n"
            +"湖北CN101200101襄阳CN101200201鄂州CN101200301孝感CN101200401黄冈CN101200501黄石CN101200601咸宁CN101200701荆州CN101200801宜昌CN101200901恩施CN101201001十堰CN101201101神农架CN101201201随州CN101201301荆门CN101201401天门CN101201501仙桃CN101201601潜江CN101201701"
            +"郑州CN101180101安阳CN101180201新乡CN101180301许昌CN101180401平顶山CN101180501信阳CN101180601南阳CN101180701开封CN101180801洛阳CN101180901商丘CN101181001焦作CN101181101鹤壁CN101181201濮阳CN101181301周口CN101181401漯河CN101181501驻马店CN101181601三峡门CN101181701济源CN101181801"
            +"济南CN101120101青岛CN101120201淄博CN101120301德州CN101120401烟台CN101120501潍坊CN101120601济宁CN101120701泰安CN101120801临沂CN101120901菏泽CN101121001滨州CN101121101东营CN101121201威海CN101121301枣庄CN101121401日照CN101121501莱芜CN101121601聊城CN101121701"
            +"呼和浩特CN101080101包头CN101080201乌海CN101080301通辽CN101080501赤峰CN101080601乌鲁木齐CN101130101克拉玛依CN101130201石河子CN101130301昌吉CN101130401吐鲁番CN101130501库尔勒CN101130601阿拉尔CN101130701阿克苏CN101130801喀什CN101130901伊犁CN101131001塔城CN101131101\n" +
            "哈密CN101131201克州CN101131501拉萨CN101140101日喀则CN101140201山南CN101140301林芝CN101140401昌都CN101140501那曲CN101140601阿里CN101140701"
            +"沈阳CN101070101大连CN101070201鞍山CN101070301抚顺CN101070401本溪CN101070501丹东CN101070601锦州CN101070701营口CN101070801阜新CN101070901辽阳CN101071001铁岭CN101071101盘锦CN101071301葫芦岛CN101071401\n"
            +"太原CN101100101大同CN101100201阳泉CN101100301晋中CN101100401长治CN101100501晋城CN101100601临汾CN101100701运城CN101100801朔州CN101100901忻州CN101101001吕梁CN101101100\n"
            +"石家庄CN101090101保定CN101090201张家口CN101090301承德CN101090402唐山CN101090501廊坊CN101090601沧州CN101090701衡水CN101090801邢台CN101090901邯郸CN101091001秦皇岛CN101091101\n"
            +"西宁CN101150101海东CN101150201黄南CN101150301海南CN101150401果洛CN101150501玉树CN101150601海西CN101150701海北CN101150801格尔林CN101150901\n"
            +"兰州CN101160101定西CN101160201平凉CN101160301庆阳CN101160401武威CN101160501金昌CN101160601张掖CN101160701酒泉CN101160801天水\n" +
            "CN101160901陇南CN101161001临夏CN101161101甘南CN101161201白银CN101161301嘉峪关CN101161401银川CN101170101石嘴山CN101170201吴忠CN101170301固原CN101170401中卫CN101170501\n";

/**
 * 通过城市的名称获取对应的城市id，如果不存在则返回 加载默认的城市(厦门)
 * @return weatherId;
 */

    public static String getCityIdByName(String cityName){
        String weatherId = null;
        int  startIndex = Common.CITYIDS.indexOf(cityName)+ cityName.length() ;// 开始截取的位置

        if (startIndex == -1) {
            return "CN101230601";
        }
        weatherId = Common.CITYIDS.substring(startIndex, startIndex + 11);

        return weatherId;
    }
    /**
     * 通过Gosn反馈回来的日期转成对应星期，如果不存在则返回 null
     * @return weekDate;
     */
    public static String getDate(String WeatherDate) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");// 定义日期格式
        Date date = null;
        try {
            date = format.parse(WeatherDate);// 将字符串转换为日期
        } catch (ParseException e) {
            e.printStackTrace();
        }
        String weekDate = getWeek(date);
        return weekDate;
    }

    public static String getWeek(Date date) {

        SimpleDateFormat sdf = new SimpleDateFormat("EEEE");
        String week = sdf.format(date);
        return week;

    }
     /**
     * 截取小时天气时间 eg: 2017-2-16 18:00
     * 保留18:00
     */
    public static String getHour(String Hour){
        String str = Hour;
        String weatherHour = str.substring(10);
        return weatherHour;
    }


}
